package main

import "fmt"

func main() {
	flag := make(chan struct{})

	sch := []chan int{
		make(chan int, 3),
	}
	go func() {
		defer close(flag)
		for i := 0; i < 10; i++ {
			select {
			case sch[len(sch)-1] <- i:
			default:
				sch = append(sch, make(chan int, 3))
			}
		}

	}()
	<-flag
	for i:=0;i<len(sch) ; i++ {
		c:=sch[i]
		close(c)
		for x:=range c{
			fmt.Println(x)
		}
	}
}
